package com.blovesoft.tokenup.util;

import android.widget.ImageView;

import com.blovesoft.tokenup.R;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.transition.DrawableCrossFadeFactory;
import com.llkj.common.util.GlideApp;

/**
 * author: zhu.px
 * e-mail: 1271901673@qq.com
 * time  : 2018/5/28
 * desc  : 图片加载
 */
public class GlideUtil {

    public static void loadImage(ImageView iv, String url) {
        GlideApp.with(iv.getContext())
                .load(url)
                .centerCrop()
                .placeholder(R.drawable.ic_launcher_background)
                .error(R.drawable.ic_launcher_background)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .transition(DrawableTransitionOptions.withCrossFade(new DrawableCrossFadeFactory.Builder().setCrossFadeEnabled(true)))
                .into(iv);
    }

    public static void loadCircleImage(ImageView iv, String url) {
        GlideApp.with(iv.getContext())
                .load(url)
                .circleCrop()
                .placeholder(R.drawable.ic_launcher_background)
                .error(R.drawable.ic_launcher_background)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .transition(DrawableTransitionOptions.withCrossFade(new DrawableCrossFadeFactory.Builder().setCrossFadeEnabled(true)))
                .into(iv);
    }

    public static void loadRoundmage(ImageView iv, String url) {
        GlideApp.with(iv.getContext())
                .load(url)
                .placeholder(R.drawable.ic_launcher_background)
                .error(R.drawable.ic_launcher_background)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .transform(new RoundedCorners(15))
                .transition(DrawableTransitionOptions.withCrossFade(new DrawableCrossFadeFactory.Builder().setCrossFadeEnabled(true)))
                .into(iv);
    }

}
